package com.yinni.controller.sys;

import com.yinni.model.sys.PageResult;
import com.yinni.model.sys.RiverEntity;
import com.yinni.service.sys.RiverService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class RiverController {

    private Logger log = LoggerFactory.getLogger(RiverController.class);

    @Resource(name = "riverServiceImpl")
    private RiverService riverService;

    /**
     * 获取rivers详细信息及相关数目
     *
     * @param pageSize
     * @param page
     * @return
     */
    @GetMapping("/rivers")
    public PageResult riversList(String loginName, int pageSize, int page) {
        PageResult pageResult = new PageResult();
        pageResult.setData(riverService.riversList(pageSize,page * pageSize));
        pageResult.setTotalCount(riverService.riversSize(pageSize,page * pageSize));
        log.info(" rivers. The method is ending");
        return pageResult;
    }

    /**
     * 新建河流信息
     *
     * @param riverEntity
     * @return
     */
    @PostMapping("/rivers/addriver")
    public RiverEntity insertRiver(@RequestBody RiverEntity riverEntity) {
        riverService.insertRiver(riverEntity);
        log.debug("addRiver. The method is ending");
        return riverEntity;
    }

    /**
     * 更新河流相关信息
     *
     * @param riverEntity
     * @param river_id
     * @return
     */
    @PutMapping("/rivers/{river_id}")
    public RiverEntity updateUser(@RequestBody RiverEntity riverEntity, @PathVariable String river_id) {
        riverService.updateRiver(riverEntity);
        log.info("river update. The method is ending");
        return riverEntity;
    }

    /**
     * 删除河道信息
     *
     * @param groupId
     * @return
     */
    @DeleteMapping("/rivers")
    public List<String> deleteRivers(@RequestBody List<String> groupId) {
        riverService.deleteRivers(groupId);
        log.info("delete success!");
        return groupId;
    }




}
